<?php
class Employeemodel extends CI_Model{

public function __construct(){

        parent::__construct();
}


public function get_num(){
  $departstr=depart_tree_result($this->db,$this->session->userdata('depart'));
  $sql="select * from employee where depart in ($departstr) and del=0  ";
  $query=$this->db->query($sql);
  $num=$query->num_rows();
  return $num;
}

public function get_emps($page,$rows){
$departstr=depart_tree_result($this->db,$this->session->userdata('depart'));
$sql="select * from employee where del=0 and depart in ($departstr) order by id DESC limit $page,$rows";
  $query=$this->db->query($sql);
  if($query->num_rows()>0){
    $arr=$query->result_array();
    foreach ($arr as $key => $value) {
        foreach ($value as $key2 => $value2) {
        	if($key2=="depart"){
                          $sql="select * from depart where id='$value2'";

                        $query=$this->db->query($sql);
                        $row=$query->row();
                         $num=$query->num_rows();
                        if($num>0){
                                $arr[$key]['departname']=$row->name;
                        }else{
                        	   
                            $arr[$key]['departname']="";
                        }

        	}elseif ($key2=="category") {
        		           $sql="select * from empcate where id='$value2'";
                        $query=$this->db->query($sql);
                        $row=$query->row();
                         $num=$query->num_rows();
                        if($num>0){
                                $arr[$key]['categoryname']=$row->name;
                        }else{
                             
                            $arr[$key]['categoryname']="";
                        }

        	}
        }
    }
  }else{
    $arr=0;
  }
  return $arr;


}





}


?>
